<template>
    <div>
        <van-nav-bar title="我的收藏" left-text="返回" left-arrow @click-left="back" />
    </div>

    <!-- 背景 -->
    <div class="bg"></div>
    <div class="info">
        <div class="products">
            <!-- 商品 -->
            <div class="products-card" v-for="(item, index) in order1">
                <div class="img-box" @click="getProcq(item.pid, index)">
                    <img :src="item.largeImg" alt=""
                        style="border-radius: 5px; height: 100%;width: 100%;margin-top: 5px;" />
                </div>
                <div class="info1">

                    <div class="name one_text">{{ item.name }}</div>
                    <div class="enname one_text">{{ item.enname }}</div>
                    <div class="price">￥{{ item.price }}</div>
                    <div class="icon"><van-icon @click="danshan1" name="delete-o" /></div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { useRouter } from 'vue-router'
import { get, post } from "../request";
import { ref } from "vue";
export default {

    setup() {


        //存放商品
        const order1 = ref([])
        const findAllLike = async (pid) => {
            const res = await get("/findAllLike", {
                params: {
                    pid,
                    tokenString: JSON.parse(localStorage.getItem('tokens'))
                }
            })
            order1.value = res.data.result
            console.log("商品收藏信息", res);
        }
        findAllLike()

        //删除方法
        const del = async (pid) => {
            const res = await post('/notlike', {
                tokenString: JSON.parse(localStorage.getItem('tokens')),
                pid,
            })
            console.log("删除", res);
            if (res.data.code == 7000) {
                order1()
            }
        }
        //单删
        // const danshan1 = (i, e) => {
        //     // 页面删除 / 数据删除
        //     console.log(i, e);
        //     order1.value.splice(i, 1)
        //     del(JSON.stringify([e]))
        //     console.log("删除1",order1.value);
        // }
        const danshan1 = (e) => {
            // 页面删除 / 数据删除
            console.log(e);
            order1.value.splice(e, 1)
            del(JSON.stringify([e]))
            console.log("删除1", order1.value);

        }
        //点击进入商品详情页
        const getProcq = (e) => {
            //console.log("e", e);
            router.push({ name: "Detail", query: { id: e } })
        }

        const router = useRouter();
        const back = () => {
            router.go(-1);
        }

        return {
            back,
            getProcq,
            order1,
            danshan1,
        }
    },

}
</script>
<style lang="less" scoped>
.products {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
}

.products-card {
    position: relative;
    width: calc(100% / 3 - 10px);
    margin: 5px;
    border-radius: 10px;

    background-color: #ffffff;
    height: 150px;
}

.name one_text {
    font-size: 16px;
    font-weight: 700;
    margin: 2px;
}

.enname one_text {
    font-size: 10px;
    color: #acacac;
    margin: 5px 10px;
}

.price {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    color: #182078;
    margin-top: 5px;
    float: left;
}

.icon {
    float: right;
    margin-top: 10px;
    margin-right: 5px;
}

.info {
    border-radius: 5px;
    position: relative;
    top: -30px;
    left: 0;
    width: 95%;
    margin: 0 auto;
    box-sizing: border-box;
    background-color: rgba(255, 255, 255, );
}

.bg {
    height: 100px;
    background-color: #ff8c8c;
}
</style>